<?php

class AccountController extends Common {

    public function __construct() {
        parent::__construct();
        $this->load->model('order');

    }

    /**
     * 用户账号支付宝管理
     */
    public function listAction() {
        $page     = $this->get('page') ? : 1;
        $pagesize = 10;
        $pagelist = $this->instance('pagelist');
        $pagelist->loadconfig();
        $where = '';
        $model = $this->model('account');
        $total = $model->count('account', 'id', $where);
        $urlparam = array(
            'page' => '{page}',
        );
        $data = $model->page_limit($page, $pagesize)->order(array('id DESC'))->select();
        $pagelist = $pagelist->total($total)->url(url('admin/account/list', $urlparam))->num($pagesize)->page($page)->output();
        $this->view->assign(array(
            'page' => $page,
            'data' => $data,
            'pagelist'=> $pagelist,
        )); //assign()对视图变量完成赋值
        $this->view->display('/admin/account/account_list');  //这里是对视图文件的加载
    }

    /**
     * 实名认证审核操作
     */
    public function operateAccountAction()
    {
        $result = ["code"=>0,"msg"=>"成功","data"=>[]];
        $id = $this->post('id');    //ca_withdraw id
        $operate = $this->post('operate');    //操作  confirm：确认  refuse：驳回
        if($operate=='confirm'){
            $status = 2;
        }elseif($operate=='refuse'){
            $status = 3;
        }else{
            $result["code"] = 1;
            $result["msg"] = "参数有误";
            echo json_encode($result);exit;
        }
        $this->load->model('account');
        $data = [
            'id'=>$id,
            'status'=>$status,  //认证状态  0：未认证  1：审核中  2：已认证 3：驳回
        ];
        $accountInfo =$this->account->accountOperate($data);	//更新用户绑定支付宝审核信息
        if(empty($accountInfo)){
            $result["code"] = 1;
            $result["msg"] = "操作失败";
            echo json_encode($result);exit;
        }
        echo json_encode($result);
    }

    /**
     * 用户实名认证详情
     * @param $id
     */
    public function accountInfoAction($id)
    {
        $id = $this->get('id');
        if(empty($id)){echo '参数有误';}
        $model = $this->model('account');
        $data = $model->getOne('id='.$id);
        $this->view->assign('data',$data);
        $this->view->display('/admin/account/account_info'); //加载视图文件
    }

    public function sfAction(){
        $username=$_POST[username];   //获取视图文件传过来的表单的值  表单我用post传值
        // $model = $this->model('member');  //实例化model 这里的两行是用fine的原有的写的，但是我感觉这样不灵活我下面又用php的写了因为我感觉还是php写的顺手，大家自己感觉什么好就用什么吧
        // $data = $model->getAll('username=?', "$username"); //用的fine的getall函数
        $sql="select * from fn_member where username='$username' ";   //sql语句  这里是php的
        $row=mysql_query($sql);  //php执行sql
        $data=mysql_fetch_assoc($row);  //获取sql语句得到的值
        $this->view->assign('data',$data); //assign()对视图变量完成赋值
        $this->view->display('sf'); //加载视图文件
    }

}
